Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var today = GetDateToday();

//起始状态为00，表示尚未评级
var currentStatus = "00";

var pdStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=IndSystemResult',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad: true
}); 
//系统评级
var systemForm = new Ext.form.FormPanel({ 
id: 'systemForm', 
renderTo:'system', 
height: 50, 
//样式 
bodyStyle: 'margin:3px', 
frame: true, 
labelWidth: 80, 
items: 
[
{
	layout:"column",
	items:[
	{
		columnWidth : .25, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'numberfield',
			id: 'adjustValue', 
			name: 'adjustValue', 
			fieldLabel: '申请评分得分',
			allowBlank: true,
			readOnly: true,
			disabled:true,
			style:'color:#000;', 
			width: 120 
		}]
	},
	{ 
		columnWidth : .25, 
        layout : "form",
        items : [{
        	  xtype: 'combo', 
 			  id: 'indSystemResult',
              store :pdStore,
              fieldLabel: '系统结果',
              valueField : 'code',
              displayField : 'name',
              allowBlank : false,
              editable: false,
              readOnly:true,
              disabled:true, 
              typeAhead : true,
              width: 120,
              mode:'local', 
              hiddenName:'indSystemResult',
              triggerAction : 'all',
              selectOnFocus : true,
		}]
	},
	{ 
		columnWidth : .25, 
        layout : "form",
        items : [{
        	xtype: 'numberfield',
			id: 'indBorderLine', 
			name: 'indBorderLine', 
			fieldLabel: '准入分数线',
			allowBlank: true,	 
			style:'color:#000;', 
			width: 120 ,
			hidden: true
        	
        }]
	}]
}
]
});

//初评
var firstForm = new Ext.form.FormPanel({ 
id: 'firstForm', 
renderTo:'first', 
height: 100, 
//样式 
bodyStyle: 'margin:3px', 
frame: true, 
labelWidth: 80, 
items: 
[{
	layout:"column",
	items:[
	{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'textarea',
			id: 'firstReason', 
			name: 'firstReason', 
			fieldLabel: '初评意见',  
			style:'color:#000;',
			allowBlank: true, 
			readOnly: true,
			disabled:true, 
            typeAhead : true,
			maxLength:100,
			maxLengthText:'最多只允许输入200个汉字',
			anchor:'98%'
		}]
	},
	{ 
		columnWidth : .5,
		items:[{ 
		    layout:"column",
			items:[
			{
				columnWidth : .5, // 该列有整行中所占百分比
		        layout : "form",
		        items : [{
				      xtype: 'combo', 
		 			  id: 'firstPdlevel',
		              store :pdStore,
		              fieldLabel: '初评结果',
		              valueField : 'code',
		              displayField : 'name',
		              emptyText : '请选择...',
		              style:'color:#000;',
		              allowBlank : true,
		              editable: false,
		              disabled:true, 
		              typeAhead : true,
		              width: 120,
		              mode:'local', 
		              hiddenName:'firstPdlevel',
		              triggerAction : 'all',
		              selectOnFocus : true,
				}]
			},
		]},
		{ 
		    layout:"column",
			items:[
			{
				columnWidth : .5, // 该列有整行中所占百分比
		        layout : "form",
		        items : [{
		        	xtype: 'textfield',
					id: 'firstUser', 
					name: 'firstUser', 
					fieldLabel: '初评人',  
					allowBlank: true,
					readOnly:true,
					disabled:true,  
					width: 120 
				}]
			},
			{ 
				columnWidth : .5, 
		        layout : "form",
		        items : [{
					xtype: 'textfield',
					id: 'firstDate', 
					name: 'firstDate', 
					fieldLabel: '评级时间',
					style:'color:#000;',  
					allowBlank: true, 
					readOnly: true,
					disabled:true,  
					width: 120 
				}]
			}]
		}]
	}]
}],
});

//
////复评
//var firstVerifyForm = new Ext.form.FormPanel({ 
//id: 'firstVerifyForm', 
//renderTo:'firstVerify', 
//height: 120, 
////样式 
//bodyStyle: 'margin:3px', 
//frame: true, 
//labelWidth: 80, 
//items: 
//[{
//	layout:"column",
//	items:[
//	{
//		columnWidth : .5, // 该列有整行中所占百分比
//      layout : "form",
//      items : [{
//      	xtype: 'textarea',
//			id: 'firstVerifyReason', 
//			name: 'firstVerifyReason', 
//			fieldLabel: '复评意见',  
//			allowBlank: true,  
//			maxLength:100,
//			maxLengthText:'最多只允许输入200个汉字',
//			anchor:'98%'
//		}]
//	},
//	{ 
//		columnWidth : .5,
//		items:[{ 
//		    layout:"column",
//			items:[
//			{
//				columnWidth : .5, // 该列有整行中所占百分比
//		        layout : "form",
//		        items : [{
//		        	 xtype: 'combo', 
//		 			  id: 'firstVerifyPdlevel',
//		              store :pdStore,
//		              fieldLabel: '复评结果',
//		              valueField : 'code',
//		              displayField : 'name',
//		              emptyText : '请选择...',
//		              allowBlank : false,
//		              editable: false,
//		              typeAhead : true,
//		              width: 120,
//		              mode:'local', 
//		              hiddenName:'firstVerifyPdlevel',
//		              triggerAction : 'all',
//		              selectOnFocus : true,
//				}]
//			}]
//		},
//		{ 
//		    layout:"column",
//			items:[
//			{
//				columnWidth : .5, // 该列有整行中所占百分比
//		        layout : "form",
//		        items : [{
//		        	xtype: 'textfield',
//					id: 'firstVerifyUser', 
//					name: 'firstVerifyUser', 
//					fieldLabel: '复评人',  
//					allowBlank: true,
//					readOnly:true,
//					disabled:true,  
//					width: 120 
//				}]
//			},
//			{ 
//				columnWidth : .5, 
//		        layout : "form",
//		        items : [{
//					xtype: 'textfield',
//					id: 'firstVerifyDate', 
//					name: 'firstVerifyDate', 
//					fieldLabel: '评级时间',
//					value: today,
//					style:'color:#000;',  
//					allowBlank: true, 
//					readOnly: true,
//					disabled:true,  
//					width: 120 
//				}]
//			}]
//		}]
//	}]
//}],
//buttonAlign:'center',
//buttons:[
//{text:"退回初评人", handler:returnToFirst},
//{text:"保存复评结果", handler:saveFirstVerifyPD},
//{text:"提交审核", handler:commitToFirstVerify}
//]
//});

//审核
var secondForm = new Ext.form.FormPanel({ 
id: 'secondForm', 
renderTo:'second', 
height: 100, 
//样式 
bodyStyle: 'margin:3px', 
frame: true, 
labelWidth: 80, 
items: 
[{
	layout:"column",
	items:[
	{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'textarea',
			id: 'secondReason', 
			name: 'secondReason', 
			fieldLabel: '审核意见',  
			allowBlank: true,  
			readOnly:true,
			disabled:true,
			anchor:'98%'
		}]
	},
	{ 
		columnWidth : .5,
		items:[{ 
		    layout:"column",
			items:[
			{
				columnWidth : .5, // 该列有整行中所占百分比
		        layout : "form",
		        items : [{
		        	 xtype: 'combo', 
		 			  id: 'secondPdlevel',
		              store :pdStore,
		              fieldLabel: '审核结果',
		              valueField : 'code',
		              displayField : 'name',
		              emptyText : '请选择...',
		              allowBlank : false,
		              editable: false,
		              typeAhead : true,
		              readOnly:true,
		              disabled:true,  
		              width: 120,
		              mode:'local', 
		              hiddenName:'secondPdlevel',
		              triggerAction : 'all',
		              selectOnFocus : true,
				}]
			}]
			
//			{ 
//				columnWidth : .5, 
//		        layout : "form",
//		        items : [{
//					xtype: 'textfield',
//					id: 'secondPdvalue', 
//					name: 'secondPdvalue', 
//					fieldLabel: 'PD(%)',
//					allowBlank: true, 
//					readOnly: true,
//					disabled:true,  
//					width: 120 
//				}]
//			}
			
		},
		{ 
		    layout:"column",
			items:[
			{
				columnWidth : .5, // 该列有整行中所占百分比
		        layout : "form",
		        items : [{
		        	xtype: 'textfield',
					id: 'secondUser', 
					name: 'secondUser', 
					fieldLabel: '审核人',  
					allowBlank: true,
					readOnly:true,
					disabled:true,  
					width: 120 
				}]
			},
			{ 
				columnWidth : .5, 
		        layout : "form",
		        items : [{
					xtype: 'textfield',
					id: 'secondDate', 
					name: 'secondDate', 
					fieldLabel: '评级时间',
					allowBlank: true, 
					readOnly: true,
					disabled:true,  
					width: 120 
				}]
			}]
		}]
	}]
}]
});
//
////认定
//var confirmForm = new Ext.form.FormPanel({ 
//id: 'confirmForm', 
//renderTo:'confirm', 
//height: 100, 
////样式 
//bodyStyle: 'margin:3px', 
//frame: true, 
//labelWidth: 80, 
//items: 
//[{
//	layout:"column",
//	items:[
//	{
//		columnWidth : .5, // 该列有整行中所占百分比
//        layout : "form",
//        items : [{
//        	xtype: 'textarea',
//			id: 'confirmReason', 
//			name: 'confirmReason', 
//			fieldLabel: '认定意见',  
//			allowBlank: true,  
//			readOnly:true,
//			disabled:true,
//			anchor:'98%'
//		}]
//	},
//	{ 
//		columnWidth : .5,
//		items:[{ 
//		    layout:"column",
//			items:[
//			{
//				columnWidth : .5, // 该列有整行中所占百分比
//		        layout : "form",
//		        items : [{
//		        	xtype: 'combo', 
//		 			  id: 'confirmPdlevel',
//		              store :pdStore,
//		              fieldLabel: '认定结果',
//		              valueField : 'code',
//		              displayField : 'name',
//		              emptyText : '请选择...',
//		              allowBlank : false,
//		              editable: false,
//		              typeAhead : true,
//		              readOnly:true,
//		              disabled:true,  
//		              width: 120,
//		              mode:'local', 
//		              hiddenName:'confirmPdlevel',
//		              triggerAction : 'all',
//		              selectOnFocus : true,
//				}]
//			},
//			{ 
//				columnWidth : .5, 
//		        layout : "form",
//		        items : [{
//					xtype: 'textfield',
//					id: 'confirmPdvalue', 
//					name: 'confirmPdvalue', 
//					fieldLabel: 'PD(%)',
//					allowBlank: true, 
//					readOnly: true,
//					disabled:true,  
//					width: 120 
//				}]
//			}]
//		},
//		{ 
//		    layout:"column",
//			items:[
//			{
//				columnWidth : .5, // 该列有整行中所占百分比
//		        layout : "form",
//		        items : [{
//		        	xtype: 'textfield',
//					id: 'confirmUser', 
//					name: 'confirmUser', 
//					fieldLabel: '认定人',  
//					allowBlank: true,
//					readOnly:true,
//					disabled:true,  
//					width: 120 
//				}]
//			},
//			{ 
//				columnWidth : .5, 
//		        layout : "form",
//		        items : [{
//					xtype: 'textfield',
//					id: 'confirmDate', 
//					name: 'confirmDate', 
//					fieldLabel: '评级时间',
//					allowBlank: true, 
//					readOnly: true,
//					disabled:true,  
//					width: 120 
//				}]
//			}]
//		}]
//	}]
//}]
//});

//系统评级表单加载数据
systemForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'rating/getRatingResult.do', 
    method:'post',
    success:function(form, action){
    	currentStatus = action.result.data.phaseStat;

    	Ext.getCmp("firstReason").setValue(action.result.data.firstReason);
    	Ext.getCmp("firstPdlevel").setValue(action.result.data.firstPdlevel);
    	Ext.getCmp("firstDate").setValue(action.result.data.firstDate);
    	Ext.getCmp("firstUser").setValue(action.result.data.firstUser);
    		
//    	Ext.getCmp("firstVerifyReason").setValue(action.result.data.firstVerifyReason);
//    	Ext.getCmp("firstVerifyPdlevel").setValue(action.result.data.firstVerifyPdlevel);
//    	Ext.getCmp("firstVerifyDate").setValue(action.result.data.firstVerifyDate);
//    	Ext.getCmp("firstVerifyUser").setValue(action.result.data.firstVerifyUser);
//    	
//    	if(currentStatus != "02")
//		 	Ext.getCmp("firstVerifyPdlevel").disable();
    		
    	Ext.getCmp("secondReason").setValue(action.result.data.secondReason);
    	Ext.getCmp("secondPdlevel").setValue(action.result.data.secondPdlevel);
    	Ext.getCmp("secondDate").setValue(action.result.data.secondDate);
    	Ext.getCmp("secondUser").setValue(action.result.data.secondUser);
    		
//    	Ext.getCmp("confirmReason").setValue(action.result.data.confirmReason);
//    	Ext.getCmp("confirmPdlevel").setValue(action.result.data.confirmPdlevel);
//    	Ext.getCmp("confirmDate").setValue(action.result.data.confirmDate);
//    	Ext.getCmp("confirmUser").setValue(action.result.data.confirmUser);
    },  
    failure:function(form,action){
     Ext.Msg.alert('提示','数据加载失败');  
    }  
});

//保存初评结果
function saveFirstVerifyPD(){
	//alert(currentStatus);
	if(currentStatus == '01' || currentStatus == '00'|| currentStatus == "07" ){
		Ext.Msg.alert('提示', '该评级尚未初评'); 
	}
	else if(currentStatus == '02'){
		//Ext.Msg.alert('提示', currentStatus); 
		if(firstVerifyForm.form.isValid()){
		firstVerifyForm.form.doAction('submit', { 
		url : 'rating/saveFirstVerifyPD.do', 
		method : 'post', 
		success : function(form, action) { 
			
			Ext.Msg.alert('提示', '保存成功！'); 
			currentStatus = action.result.data.phaseStat;
			//alert(currentStatus);
		}, 
		failure : function(form, action) { 
			Ext.Msg.alert('提示', '保存失败！'); 
		} 
		});  
		}
	}else{
		Ext.Msg.alert('提示', '您已提交审核，不能重复提交'); 
	}
}


function commitToFirstVerify(){
	if(currentStatus == '01' || currentStatus == '00'|| currentStatus == "07" ){
		Ext.Msg.alert('提示', '该评级尚未初评'); 
	}
	else if(currentStatus == '02'){
		//Ext.Msg.alert('提示', currentStatus); 
		if(firstVerifyForm.form.isValid()){
		firstVerifyForm.form.doAction('submit', { 
		url : 'rating/saveFirstVerifyPD.do', 
		method : 'post', 
		success : function(form, action) { 
			
			Ext.Msg.alert('提示', '保存成功！'); 
			currentStatus = action.result.data.phaseStat;
			//alert(currentStatus);

			if(currentStatus == '01' || currentStatus == '00'|| currentStatus == "07" ){
				Ext.Msg.alert('提示', '该评级尚未初评'); 
			}
			else if(currentStatus == "02" ){
				Ext.Ajax.request({
						url:'rating/commitFirstVerifyPD.do',
						method:'POST',
						success:function(response){
							var json = Ext.util.JSON.decode(response.responseText);
						 	currentStatus = json.phaseStat;
							if(currentStatus != "02")
							 	Ext.getCmp("firstVerifyPdlevel").disable();
							Ext.MessageBox.alert("提示","提交成功！");
			
						 	//alert(currentStatus);
						},failure:function(){
							Ext.MessageBox.alert("提示", "操作失败！"); 
						}
					});  	
			}else{
				Ext.Msg.alert('提示', '您已提交审核，不能重复提交'); 
			}
			
		}, 
		failure : function(form, action) { 
			Ext.Msg.alert('提示', '保存失败！'); 
		} 
		});  
		}
	}else{
		Ext.Msg.alert('提示', '您已提交审核，不能重复提交'); 
	}
	
}


function returnToFirst(){
	if(currentStatus == '01' || currentStatus == '00'|| currentStatus == "07" ){
		Ext.Msg.alert('提示', '该评级尚未初评'); 
	}
	else if(currentStatus == "02" ){
		Ext.Ajax.request({
				url:'rating/returnToFirst.do',
				method:'POST',
				success:function(response){
					Ext.MessageBox.alert("提示","退回成功！");
				 	var json = Ext.util.JSON.decode(response.responseText);
				 	currentStatus = json.phaseStat;
				 	//alert(currentStatus);
				},failure:function(){
					Ext.MessageBox.alert("提示", "退回失败！"); 
				}
			});  	
	}else{
		Ext.Msg.alert('提示', '您已提交审核，请通过审核人员退回'); 
	}
}

//取当前时间
function GetDateToday()
 {
  var d,s;
  d = new Date();
  s = d.getFullYear() + "-";             //取年份
  s = s + (d.getMonth() + 1) + "-";//取月份
  s += d.getDate() + " ";         //取日期
  
 // s += d.getHours() + ":";       取小时
  //s += d.getMinutes() + ":";    取分
 // s += d.getSeconds();         取秒
  
  return(s);  
 
 } 

}); 